<%@ page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="com.yaodian100.core.common.utils.ServerValue"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ taglib uri="http://www.yaodian100.com/jsp/yaodian100" prefix="yaodian100" %>
<%@ include file="/taglibs.jsp"%>
<script type="text/javascript" charset="UTF-8" src="/js/formValidator.js" charset="UTF-8"></script>
<script type="text/javascript" charset="UTF-8" src="/js/formValidatorRegex.js" charset="UTF-8"></script>
<s:actionerror cssClass="errmsg"/>
<s:actionmessage cssClass="errmsg"/>
  <h1>编辑资料 - 批次修改换货作业</h1>
  <div class="batchstep">
    <div class="batchstep-2">
      <span class="step1">Step 1：查寻商品/选取商品</span>
      <span class="onstep2">Step 2：编辑资料</span>
      <span class="step3">Step 3：核对资料/完成编辑</span>
    </div>
  </div>
<script language="javascript">
$().ready(function() {

	$("#oldsubmit").click(function() {
		$("#dataoldornew").val("old");
		$(".sumitdisable").attr("disabled",true);     
		$("#nextsubmit").hide();
		$("#errtable").hide();	
		$("#confirmForm").submit();		
	});

	$("#mainSubmit").click(function(){
		if ( "" == $("#MultiFile8_F1").val()){
			alert("尚未选择上传档案，请重新选择！");
			return false;
		}
	});
	
});

function validateForm() {
	var isCorrect = true;
	cleanTip();
	for(var i = 0; i < $('select[id^=returnRule_]').length; i++) {
		var oid = $('select[id^=returnRule_]')[i].id;
		if( $('#' + oid).val() == '' ) {
			isCorrect = false;
			var id = oid.replace('returnRule_', '');
			appendTip(oid, '请输入商品编号：' + id + ' 的退换货条件', true);
		}
	}
	return isCorrect;
}

function applyAll() {
	$('#msgRR').hide();
	if($('#tmp_returnRule').val() != '' ) {
		$('select[id^=returnRule_] > option').each(function() {
			if($(this).text() == $("#tmp_returnRule").find(":selected").text())
				$(this).attr("selected", "selected");
		});
	} else {
		$('#msgRR').show();
		$('#errMsg').text('请选择退换货条件');
		return
	}
	if( validateForm() ) {
		$("#dataoldornew").val("new");
		$("#oldsubmit").attr("disabled",true); 
		$("#nextsubmit").hide();
		$("#errtable").hide();	
		$("#confirmForm").submit();
	}
}

<%-- 清空提示 --%>
function cleanTip() {
	$("span:[id^=Tip_]").hide();
	$("span:[id^=Tip_]").text('');
}
<%-- 附加提示 --%>
function appendTip(id, msg, isFocus) {
	if( !(isFocus == true || isFocus == false) ) 
		isFocus = true;
	
	var target = $('#Tip_' + id);
	if(target.text().length > 0) {
		appendWord(target, msg);
	} else
		target.text(msg);
	target.show();
	if(isFocus)
		$('#' + id).focus();
}

function appendWord(origin, apptext){
	if(origin.text().length==0){
		origin.text(apptext);
	}else{
		origin.text(origin.text()+', '+apptext);
	}
}
</script>
  <!-- div class="data-form"> -->
	<s:form action="downloadFile.do" id="confirmForm" method="post">
	<s:hidden name="paramBatchEventId"/>
    <img src="/images/ecadmin/bianjiziliaoliucheng.jpg"></img>
	<div class="tipmsg" style="width:53%"><ul><li>系统会将你所选定的商品自动生成Excel报表，请在信息编辑完成后，下载报表。<br/>此阶段具有时效性，请在<Strong>25分钟</Strong>内完成编辑，并上传相关Excel报表</li></ul></div>
     <h2>下载报表</h2>	
		<table class="tb-edit" style="width:53%;clear:none;">
          <tr>
          	<th>退换货条件</th>
          	<td>
          	<s:select name="tmp_returnRule" class="sumitdisable" id="tmp_returnRule" list="menuOrderReturnRule.options" listKey="key" listValue="value.name" headerKey="" headerValue=""/>
          	<ul id="msgRR" class="errmsg" style="display:none"><li><span id="errMsg"></span></li></ul>
          	</td>
          </tr>
          <tr>
          	<th></th>
          	<td>
          	<input type="button" class="sumitdisable" value="全部套用，下载Excel报表" name="submit1" onclick="applyAll()">
          	<input type="hidden" id="dataoldornew" name="dataoldornew">
            <c:if test="${!empty event.modifyDate}"><input type="button" id="oldsubmit" value="下载之前上传的报表 "></c:if>
          	</td>
          </tr>
        </table>
       <div style="display:none;">
		<s:iterator value="detailMap" var="map" status="idx">
           <s:select name="detailMap['%{#map.key}'].dataNewMap['returnRule']" id="returnRule_%{#map.key}" list="menuOrderReturnRule.options" listKey="key" listValue="value.name" headerKey="" headerValue="" />
		</s:iterator></div></s:form>
 		<br />  
		<h2>上传报表</h2>
      	 <div class="tipmsg"  style="width:53%"><ul><li>请将核对编辑后的报表上传。</li></ul></div>         
		<s:form action="uploadFile.do" method="post" enctype ="multipart/form-data">
	    	<table style="width:53%;clear:none;" border="0" align="left" class="tb-data">		
		        <tr>
		          	<td><input id="MultiFile8_F1" class="multi accept-xls" maxlength="1" type="file" name="upload"  accept="xls"/>
		          	<s:submit id="mainSubmit" value="上传Excel报表" /><br><br>
		         	<c:if test="${!empty step2Upload}">
			         	<div style="width:100%;font-size: 15px;" id="errtable" >
			         	上传成功${uploadSuccess}笔<br />
			         	上传失败${uploadErr}笔<br />
				         	<c:if test="${!empty errId}">
				         	上传失败的编号（最多显示20笔）:
					         	<c:forEach items="${errId}" var="errId" varStatus="rows_index">
					         	${errId} / 
					         	</c:forEach>	         		
				         	</c:if>
			         	</div>
		         	</c:if>
		         	</td>
		       </tr>
	    	 </table>
	   </s:form>
       <s:form action="confirm.do">
        <table width="560"  border="0"><tr height="40"><td>
     	 <br /><c:if test="${empty event.modifyDate}"><a href="changePage.do" class="pstep">﹤回上一步</a></c:if> 
      	<c:if test="${uploadSuccess>0 and uploadErr<=0}">
      		<input type="submit" id="nextsubmit" value="上传完成！下一步﹥" name="submit1" class="nstep" ><br />
		</c:if>
		</td></tr></table>
     </s:form>
